package com.fetch.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JTextField;

import com.download.exception.DownloadException;
import com.download.utils.LogUtil;

public class OpenFileActionListener implements ActionListener {

    private JTextField directory;
    private JTextField fileName;
    private String command = "cmd /c start ";
    
    public OpenFileActionListener(JTextField directory, JTextField fileName) {
        super();
        this.directory = directory;
        this.fileName = fileName;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        try {
             LogUtil.info(command + directory.getText().replace("/", File.separator) + File.separator + fileName.getText());
             Runtime.getRuntime().exec(command + directory.getText().replace("/", File.separator) + File.separator + fileName.getText());
        } catch (Exception e1) {
            throw new DownloadException("OpenFileActionListener.actionPerformed()", e1);
        }
    }
}
